<!DOCTYPE html>
<html lang="en">
<head>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>智能化安全管控平台</title>
        <!-- 依 赖 样 式 -->
        <link rel="stylesheet" href="component/pear/css/pear.css" />
        <!-- 加 载 样 式 -->
        <link rel="stylesheet" href="admin/css/loader.css" />
        <!-- 布 局 样 式 -->
        <link rel="stylesheet" href="admin/css/admin.css" />
    </head>
</head>
<body style="height: auto;">
    <form class="layui-form" action="">
        <input type="hidden" name="username" value="${username!}">
        <div class="layui-tab layui-tab-brief" style="margin: 20px 10px"  lay-filter="docDemoTabBrief">
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-inline" style="width:300px">
                    <input type="password"  name="oldpwd" id="oldpwd" lay-verify="required" required autocomplete="off" placeholder="请输入旧密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline" style="width:300px">
                    <input type="password"  name="password" id="password" lay-verify="required" required autocomplete="off" placeholder="请输入新密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline" style="width:300px">
                    <input type="password"  name="password2" id="password2" lay-verify="required" required autocomplete="off" placeholder="请确认密码" class="layui-input">
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
            </div>
        </div>
    </form>
    <script src="component/layui/layui.js"></script>
    <script src="component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery','popup'], function () {
            let form = layui.form;
            let $ = layui.jquery;
            var popup = layui.popup;

            form.on('submit(user-save)', function (data) {
                if (data.field.password===data.field.password2) {
                    $.ajax({
                        url: '${ctxPath}/updpwd',
                        data: JSON.stringify(data.field),
                        dataType: 'json',
                        contentType: 'application/json',
                        type: 'post',
                        success: function (result) {
                            console.log(result);
                            if (result.code == 200) {
                                layer.msg(result.message, {icon: 1, time: 2000}, function () {
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                    top.location.href="${ctxPath}/login";
                                });
                            } else if(result.code == 400) {
                                layer.msg(result.message, {icon: 2, time: 2000});
                            } else{
                                layer.msg(result.message, {icon: 2, time: 2000});
                            }
                        }
                    })
                }else{
                    layer.msg('新密码和确认密码不一致', {icon: 2, time: 2000});
                }
                return false;
            });
        })
    </script>
</body>
</html>